package Controller;

import Service.BusLineService;
import com.example.demo.BusLine;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bus-lines")
public class BusLineController {
    private final BusLineService busLineService;

    public BusLineController(BusLineService busLineService) {
        this.busLineService = busLineService;
    }

    @PostMapping
    public void addBusLine(@RequestBody BusLine busLine) {
        busLineService.addBusLine(busLine);
    }

    @PutMapping("/{id}")
    public void updateBusLine(@PathVariable Long id, @RequestBody BusLine busLine) {
        busLine.setId(id);
        busLineService.updateBusLine(busLine);
    }

    @DeleteMapping("/{id}")
    public void deleteBusLine(@PathVariable Long id) {
        busLineService.deleteBusLine(id);
    }

    @GetMapping("/{id}")
    public BusLine getBusLineById(@PathVariable Long id) {
        return busLineService.getBusLineById(id);
    }

    @GetMapping
    public List<BusLine> getAllBusLines() {
        return busLineService.getAllBusLines();
    }

    @GetMapping("/search")
    public List<BusLine> getBusLinesByName(@RequestParam String name) {
        return busLineService.getBusLinesByName(name);
    }

    @GetMapping("/search")
    public List<BusLine> getBusLinesByRouteNumber(@RequestParam String routeNumber) {
        return busLineService.getBusLinesByRouteNumber(routeNumber);
    }
}

